home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group01b.txt
/
000041_icon-group-sender_Thu Mar 1 08:43:25 2001.msg
< prev
next >
Wrap
Internet Message Format
|
2002-01-03
|
3KB
Return-Path: <icon-group-sender>
Received: (from root@localhost)
by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id f21FhLc22736
for icon-group-addresses; Thu, 1 Mar 2001 08:43:21 -0700 (MST)
Message-Id: <200103011543.f21FhLc22736@baskerville.CS.Arizona.EDU>
Date: Thu, 01 Mar 2001 09:59:23 -0500
From: "Steve Graham" <Steve_Graham@labcorp.com>
To: <icon-group@cs.arizona.edu>, <cary@cup.hp.com>
Subject: Re: New Scientist puzzle
Content-Disposition: inline
X-MIME-Autoconverted: from quoted-printable to 8bit by baskerville.CS.Arizona.EDU id f21Exu821117
Errors-To: icon-group-errors@cs.arizona.edu
Status: RO
Content-Length: 2038
Cary,
Nice, compact, understandable solution.
Steve
>>> Cary Coutant <cary@cup.hp.com> 02/28/01 06:05PM >>>
My solution recognizes that map() can do most of the work for you:
map("62419409", "62419409", "VIERNEUN") == "VIERNEUN"
map("VIERNEUN", "VIERNEUN", "62419409") == "62419409"
These two tests verify that each letter is used, and that each digit maps
to a different letter.
I then made a list of candidate solutions that satisfy the first
condition, and used two tables to cross-reference the numbers to find the
solution(s) where one number uniquely determines the other.
Interestingly, the puzzle works in English with one minor change. "FOUR
NINE" doesn't have a solution, but "FIVE NINE" does.
-cary
procedure main(args)
local pat1, pat2, pats
local t1, t2, solutions
local num1, num2, nums
local soln
# Get patterns from the command line
pat1 := args[1] | "VIER"
pat2 := args[2] | "NEUN"
pats := pat1 || pat2
# Initialize cross-reference tables
# and list of solutions
t1 := table(0) # t1[n] counts solutions of form (n,x)
t2 := table(0) # t2[n] counts solutions of form (x,n)
solutions := []
# Generate all possible solutions and check against patterns
every num1 := gen_squares(*pat1) &
num2 := gen_squares(*pat2) do {
nums := num1 || num2
if map(pats, pats, nums) == nums &
map(nums, nums, pats) == pats then {
t1[num1] +:= 1
t2[num2] +:= 1
put(solutions, [num1, num2])
}
}
# Look for solutions where each number
# uniquely determines the other
while soln := get(solutions) do
if t1[soln[1]] = t2[soln[2]] = 1 then
write(soln[1], " ", soln[2])
end
# Generate squares of given length
procedure gen_squares(len)
local n, inc
n := 1
inc := 3
repeat {
if *n > len then fail
if *n = len then suspend string(n)
n +:= inc
inc +:= 2
}
end